<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>DOM常用事件</title>
</head>

<body>
    <!-- autofocus：聚焦 -->
    <input type="text" id="user" placeholder="请输入关键字" autocomplete="off" />
    <script>
        let userEle = document.getElementById("user");

        // 获取焦点
        userEle.addEventListener("focus", function () {
            console.log("获取焦点");
        });

        // 失去焦点
        userEle.addEventListener("blur", function () {
            console.log("失去焦点");
        });

        // 键盘按下并抬起事件
        userEle.addEventListener("keyup", function (event) {
            // event事件对象
            console.log("keyup", event.code, event.keyCode);
            if (event.keyCode === 13) {
                alert("回车键登录");
            }
        });
    </script>
</body>

</html>